import * as constants from './constants';
import { fromJS } from 'immutable'

const defaultState = fromJS({
    topPicList: [],
    articleList: [],
    recommendList: [],
    showScroll: false,
    writerDataList: []
})


export default (state = defaultState, action) => {
    switch (action.type) {
        case constants.SET_HOME_DATA:
            return state.merge({
                topPicList: fromJS(action.topPicList),
                articleList: fromJS(action.articleList),
                recommendList: fromJS(action.recommendList),
            })
        case constants.SET_LOAD_MORE:
            return state.merge({
                articleList: state.get('articleList').concat(action.articleList),
            })
        case constants.TOGGLE_TOP_SHOW:
            return state.merge({
                showScroll: action.show,
            })
        case constants.SET_WRITER_DATA:
            return state.merge({
                writerDataList: action.writerDataList,
            })
        default:
            return state
    }
}